<%@page import="interfaces.DALException"%>
<%@page import="java.util.List"%>
<%@page import="dto_objects.*"%>
<%@page import="java.util.ArrayList"%>
<%@page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>

<% 
String login = "<form action=\"LoginServlet\">"+
		"Username:<br>"+
		"<input type=\"text\" name=\"un\"><br>"+
		"Password:<br>"+
		"<input type=\"text\" name=\"pw\">"+
		"<input type=\"submit\" value=\"log In\">"+
		"&nbsp;"+
		"</form>";
%>


<script type="text/javascript" src="../javascripts/jquery-latest.pack.js"></script>
<script type="text/javascript" src="../javascripts/popup.js"></script>

<jsp:useBean id="func" class="Function.FunctionLIBRARY" scope="session"/>  

<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
	<title>Update User</title>
	<link rel="stylesheet" type="text/css" href="../NewStyle.css">
</head>
<body>
	<div id=topBox>
			<div id=searchField>
				<form action="../Web/MainPage.jsp">
				<input type="text" name="searchText"> 
				<input type="submit" value="">
				<a id="aSearchButton" href="../Search/aSearch.jsp">Advanced search</a>
				</form>			
			</div>
	
			<div id=login>
				<%out.print(func.getClass().getName());
				if(session.getAttribute("currentSessionUser") == null){
					session.setAttribute("userMENU", null);
					out.print("<a class=myButton href=\"#loginField\" name=\"loginFieldClick\">Login</a>");
				}else{
					out.print("<form action=\"../LoginServlet\">"+
							"<input class=myButton type=\"submit\" value=\"Log Out\" name=\"logout\">"+
							"</form>");
				}
				%>
				
				
			</div>
	</div>
	<div id=main>
		<div id=header>

		</div>
		<div id=content>
			<div id=data>
<form method="GET">
<%
if (request.getMethod().equals("POST") && request.getParameter("CPR") != null) {
	if(request.getParameter("action").equalsIgnoreCase("Submit")){
		int usrID = Integer.parseInt(request.getParameter("User ID"));;
		String Rights = "user" ;
		String Login = request.getParameter("Login");
		String Password = request.getParameter("Password");
		int CPR = Integer.parseInt(request.getParameter("CPR"));
		String Name = request.getParameter("Name");
		String Address = request.getParameter("Address");
		int Zip = Integer.parseInt(request.getParameter("Zip Code"));
		int Phone = Integer.parseInt(request.getParameter("Phone"));
		String Email = request.getParameter("Email");
		try{
 	  		func.updateUser(new UserDTO(usrID,Rights,Login,Password,CPR,Name,Address,Zip,Phone,Email));			
		}catch(DALException e){
			out.print(e.getMessage());
		}
		}
	}
%>
<div class=tabledesign style="float:left;">
<%	
	out.print("<table id=\"tabledesign\" align=center border=solid 1px>");
	out.print("<tr>");
	out.print("<td>User ID </td>");
	out.print("<td>Rights </td>");
	out.print("<td>Login </td>");
	out.print("<td>Password </td>");
	out.print("<td>CPR </td>");
	out.print("<td>Name </td>");
	out.print("<td>Address </td>");
	out.print("<td>Zip Code </td>");
	out.print("<td>Phone </td>");
	out.print("<td>Email </td>");
	out.print("</tr>");
		out.print("<tr>");
		out.print("<td>"+"<input type=\"text\" name=\"User ID\" value=\"\" size=2>"+"</td>"); 
		out.print("<td>"+"<select name=\"Rights\">");
		out.print("<option value=null selected>Pick Rights</option>");
			out.print("<option value=\"User\">"+"User"+"</option>");
			out.print("<option value=\"Libarian\">"+"Libarian"+"</option>");
			out.print("<option value=\"Admin\">"+"Admin"+"</option>");
		out.print("<td>"+"<input type=\"text\" name=\"Login\" value=\"\" size=2>"+"</td>"); 
		out.print("<td>"+"<input type=\"text\" name=\"Password\" value=\"\" size=5>"+"</td>");
		out.print("<td>"+"<input type=\"text\" name=\"CPR\" value=\"\" size=2>"+"</td>"); 
		out.print("<td>"+"<input type=\"text\" name=\"Name\" value=\"\" size=2>"+"</td>"); 
		out.print("<td>"+"<input type=\"text\" name=\"Address\" value=\"\" size=2>"+"</td>"); 
		out.print("<td>"+"<input type=\"text\" name=\"Zip Code\" value=\"\" size=5>"+"</td>"); 
		out.print("<td>"+"<input type=\"text\" name=\"Phone\" value=\"\" size=2>"+"</td>"); 
		out.print("<td>"+"<input type=\"text\" name=\"Email\" value=\"\" size=2>"+"</td>"); 
		out.print("</tr>");
	out.print("</table>");

	
%>
</div>
<input type="submit" name="action" value="Submit">
</form>
		
			</div>
		${userMENU}
		</div>
	</div>

<div id="loginField" class="window">
	<form action="../LoginServlet">
			Username:
			<input type="text" name="un"><br>
			Password:
			<input type="text" name="pw"><br>
			<input type="submit" value="Log In">
		</form>	
		<br>
	<a href="#"class="close" align=right style="color: #333;text-align: right;text-decoration: none;">Close</a>
</div>	
<div id="mask"></div>

</body>
</html>